package com.xm.dao.background;

import com.xm.entity.CommodityInsuranceType;
import com.xm.util.BaseUtil;
import org.intellij.lang.annotations.Language;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 商品保险
 * @author 康文程
 * @date 2024-1-18 上午 10:19
 */
public class CommodityInsuranceTypeDao extends BaseUtil {
    /**
     * 查询全部商品保险类型
     *
     * @return 商品保险类型列表
     */
    public List<CommodityInsuranceType> getAllCommodityInsuranceTypes() {
        @Language("sql")
        String sql = "SELECT * FROM commodity_insurance_type";
        ResultSet rs = null;
        List<CommodityInsuranceType> insuranceTypeList = new ArrayList<>();
        try {
            rs = executeQuery(sql);
            while (rs.next()) {
                CommodityInsuranceType insuranceType = new CommodityInsuranceType();
                insuranceType.setInsuranceTypeId(rs.getInt("insurance_type_id"));
                insuranceType.setInsuranceTypeTitle(rs.getString("insurance_type_title"));
                insuranceType.setInsuranceTypeLogo(rs.getString("insurance_type_logo"));
                insuranceTypeList.add(insuranceType);
            }
        } catch (SQLException e) {
            throw new RuntimeException("查询失败", e);
        } finally {
            close(rs);
            close(null);
        }
        return insuranceTypeList;
    }
}
